package stu.info.student.info.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import stu.info.student.info.entity.Admin;
import stu.info.student.info.entity.Sloc;
import stu.info.student.info.entity.Student;
import stu.info.student.info.mapper.adminMapper;
import stu.info.student.info.mapper.slocMapper;
import stu.info.student.info.mapper.studentMapper;

import java.util.List;

@Slf4j
@Api(tags ="学生管理模块")
@RestController
@RequestMapping("/student")
public class studentController {
    @Autowired
    private studentMapper studentMapper;

    @ApiOperation("添加学生")
    @PostMapping("/add")
    int addStudent(@RequestBody Student student)
    {
        studentMapper.insert(student);
        log.debug("添加学生成功>>>{}",student);
        return 200;
    }

    @ApiOperation("删除学生")
    @PostMapping("/delete")
    int deleteStudent(Long sno)
    {
        studentMapper.deleteById(sno);
        log.debug("删除学号为{}的学生成功...>>>",sno);
        return 200;
    }

    @ApiOperation("查询学生")
    @PostMapping("/select")
    List<Student> getStudent()
    {
        return studentMapper.select();
    }

    @ApiOperation("修改学生信息")
    @PostMapping("/update")
    int updateStudent(@RequestBody Student student)
    {
        studentMapper.updateById(student);
        log.debug("修改学号为{}的学生成功...>>>",student.getSno());
        return 200;
    }

}
